﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetAssist.Math;
//using System.Collections;

namespace NetAssistTests
{
  [TestClass()]
  public class AnalyzerTests
  {
    [TestMethod()]
    public void AnalyzerTest1()
    {
      double[] inputs = new double[] { 11.15, 19.40, 33.65, 53.90, 80.15, 112.40, 150.65 };

      Analyzer analyzer = new Analyzer(inputs);

      Assert.IsTrue(analyzer.Formula(8) == 194.90);
      Assert.IsTrue(analyzer.Formula(9) == 245.15);
      Assert.IsTrue(analyzer.Formula(9.5) == 272.525);

      Assert.IsTrue(analyzer.ToString() == "3X^2 - 3/4X + 8 9/10");

      inputs = new double[] { 1, 4, 9 };
      analyzer = new Analyzer(inputs);
      Assert.IsTrue(analyzer.ToString() == "X^2");

      inputs = new double[] { -1, -4, -9 };
      analyzer = new Analyzer(inputs);
      Assert.IsTrue(analyzer.ToString() == "-X^2");

      try
      {
        Random r = new Random();
        inputs = LinqLib.Sequence.Enumerator.Generate<double>(25, () => r.NextDouble() * 100).ToArray();
        Analyzer analyzer2 = new Analyzer(inputs);
        Assert.Fail();
      }
      catch (Exception ex)
      {
        Assert.IsTrue(ex.GetType() == typeof(SequenceTooComplexException));
      }
    }
  }
}
